#!/bin/bash
# 
# Copyright (c) 2007, Homebrew Mobile Phone Club
# All rights reserved.
# 
# Redistribution  and  use  in  source  and  binary  forms,  with  or  without
# modification, are permitted provided that the following conditions are met:
# 
#  * Redistributions of  source code must  retain the above  copyright notice,
#    this list of conditions and the following disclaimer.
# 
#  * Redistributions in binary form must reproduce the above copyright notice,
#    this list of conditions and the following disclaimer in the documentation
#    and/or other materials provided with the distribution.
# 
#  * Neither the name  of the Homebrew Mobile Phone Club nor  the names of its
#    contributors may be used to endorse or promote products derived from this
#    software without specific prior written permission.
# 
# THIS SOFTWARE IS PROVIDED BY  THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY  EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT  LIMITED TO, THE
# IMPLIED WARRANTIES  OF MERCHANTABILITY AND FITNESS FOR  A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO  EVENT SHALL THE  COPYRIGHT OWNER OR  CONTRIBUTORS BE
# LIABLE  FOR  ANY  DIRECT,   INDIRECT,  INCIDENTAL,  SPECIAL,  EXEMPLARY,  OR
# CONSEQUENTIAL  DAMAGES  (INCLUDING,  BUT  NOT  LIMITED  TO,  PROCUREMENT  OF
# SUBSTITUTE GOODS  OR SERVICES;  LOSS OF USE,  DATA, OR PROFITS;  OR BUSINESS
# INTERRUPTION)  HOWEVER CAUSED  AND ON  ANY THEORY  OF LIABILITY,  WHETHER IN
# CONTRACT,  STRICT LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE OR  OTHERWISE)
# ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE,  EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# This script updates the XU710_HBMOBILE003 image to the XU710_HBMOBILE004
# image.

export PROJECTS=$HOME/Projects
export DOWNLOADS=$HOME/Library/Downloads
export LOCAL_BIN=$HOME/bin

# Make Directories
mkdir -p $PROJECTS
mkdir -p $DOWNLOADS
mkdir -p $LOCAL_BIN

# Download Things
cd $DOWNLOADS
wget -O buildify http://hbmobile.org/downloads/XU710_HBMOBILE004/buildify
wget -O minirc.dfl http://hbmobile.org/downloads/XU710_HBMOBILE004/minirc.dfl
wget -O sources.list http://hbmobile.org/downloads/XU710_HBMOBILE004/sources.list
wget -O sudoers http://hbmobile.org/downloads/XU710_HBMOBILE004/sudoers
wget -O bashrc http://hbmobile.org/downloads/XU710_HBMOBILE004/bashrc

# Copy the new version of buildify into ~/bin
chmod 755 $DOWNLOADS/buildify
mv $DOWNLOADS/buildify $LOCAL_BIN

# Copy the new version of .bashrc into ~
mv $DOWNLOADS/bashrc $HOME/.bashrc

# Update /etc/sudoers so we don't have to keep entering the password
sudo chown root $DOWNLOADS/sudoers
sudo chgrp root $DOWNLOADS/sudoers
sudo chmod 440 $DOWNLOADS/sudoers
sudo mv $DOWNLOADS/sudoers /etc/sudoers

# Update /etc/apt/sources.list so we're not prompted for the CDROM
sudo chown root $DOWNLOADS/sources.list
sudo chgrp root $DOWNLOADS/sources.list
sudo chmod 644 $DOWNLOADS/sources.list
sudo mv $DOWNLOADS/sources.list /etc/apt/sources.list
sudo apt-get update

# Install your favorite packages
sudo apt-get -y --force-yes install subversion minicom lrzsz bitbake monotone python-psyco g++ patch help2man diffstat texi2html texinfo cvs gawk libncurses5-dev

# Install minicom defaults
sudo chown root $DOWNLOADS/minirc.dfl
sudo chgrp root $DOWNLOADS/minirc.dfl
sudo chmod 644 $DOWNLOADS/minirc.dfl
sudo mkdir -p /etc/minicom
sudo mv $DOWNLOADS/minirc.dfl /etc/minicom/minirc.dfl

# Make the source repository
sudo mkdir -p /usr/share/sources
sudo chmod 0777 /usr/share/sources

# Check out the OE tree
#cd $PROJECTS
#svn co https://gumstix.svn.sourceforge.net/svnroot/gumstix/trunk gumstix-oe
